/**
 * @file       EventQueue.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 20, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "EventQueue.h"
#include "errorcode.h"
#include "typedefine.h"
#include "IEvent.h"
#include "ExectuteZone.h"
namespace NS_LCD_AFW
{

CMutex CEventQueue::m_sMutex;

CEventQueue::CEventQueue()
{
}

CEventQueue::~CEventQueue()
{
}

int CEventQueue::addEvent(IEvent *pEvent)
{
	CExectuteZone zone(&m_sMutex);
	if (NULL == pEvent)
	{
		return ERR_NULL_POINTER;
	}
	this->m_eventQueue.push(pEvent);

	return ERR_SUCCESS;
}

bool CEventQueue::peekEvent(IEvent *& pEvent) const
{
	CExectuteZone zone(&m_sMutex);
	if (m_eventQueue.empty())
	{
		pEvent = NULL;
		return false;
	}
	pEvent = m_eventQueue.front();
	return true;
}

bool CEventQueue::getEvent(IEvent *& pEvent)
{
	CExectuteZone zone(&m_sMutex);
	if (m_eventQueue.empty())
	{
		pEvent = NULL;
		return false;
	}
	pEvent = m_eventQueue.front();

	m_eventQueue.pop();
	return true;

}

} /* namespace NS_LCD_AFW */
